/* =========================================================
 * ====                   WARNING                        ===
 * =========================================================
 * The code in this tab has been generated from the GUI form
 * designer and care should be taken when editing this file.
 * Only add/edit code inside the event handlers i.e. only
 * use lines between the matching comment tags. e.g.

 void myBtnEvents(GButton button) { //_CODE_:button1:12356:
     // It is safe to enter your event code here  
 } //_CODE_:button1:12356:
 
 * Do not rename this tab!
 * =========================================================
 */

public void siteAlt_Enter(GTextField source, GEvent event) { //_CODE_:siteAltitudeText:269606:
  siteAltDirty = true;
} //_CODE_:siteAltitudeText:269606:

public void goAlt_Enter(GTextField source, GEvent event) { //_CODE_:goAltitudeText:468232:
  goAltitudeDirty = true; 
} //_CODE_:goAltitudeText:468232:

public void mainAlt_Enter(GTextField source, GEvent event) { //_CODE_:mainAltText:416133:
  mainAltDirty = true;
} //_CODE_:mainAltText:416133:

public void stageAlt_Enter(GTextField source, GEvent event) { //_CODE_:stageAltText:328862:
  stageAltDirty = true; 
} //_CODE_:stageAltText:328862:

public void stageVtext_Enter1(GTextField source, GEvent event) { //_CODE_:stageVelText:381410:
  stageVelDirty = true;
} //_CODE_:stageVelText:381410:

public void setSiteAlt_Click1(GButton source, GEvent event) { //_CODE_:setAltButton:724157:
  String s = siteAltitudeText.getText();
  if (isInt(s)) {
    int alt = int(s);
    displayText.scrollText("Sending Site Altitude = " + str(alt));
    theRocket.setSiteAlt(alt);
    siteAltUpdate = true;
  } else {
    displayText.scrollText("Error: '" + s + "' is not a number");
  }
} //_CODE_:setAltButton:724157:

public void mainAltButton_Click1(GButton source, GEvent event) { //_CODE_:setMainButton:564051:
  String s = mainAltText.getText();
  if (isInt(s)) {
    int alt = int(s);
    displayText.scrollText("Sending Main Deploy = " + str(alt));
    theRocket.setMainAlt(alt);
    mainAltUpdate = true;
  } else {
    displayText.scrollText("Error: '" + s + "' is not a number");
  }
} //_CODE_:setMainButton:564051:

public void setGoAlt_Click1(GButton source, GEvent event) { //_CODE_:setGoAltButton:980633:
  String s = goAltitudeText.getText();
  if (isInt(s)) {
    int alt = int(s);
    displayText.scrollText("Sending GO Altitude = " + str(alt));
    theRocket.setGoAlt(alt);
    goAltUpdate = true;
  } else {
    displayText.scrollText("Error: '" + s + "' is not a number");
  }
} //_CODE_:setGoAltButton:980633:

public void setStageAlt_Click1(GButton source, GEvent event) { //_CODE_:setStageAltButton:759707:
  String s = stageAltText.getText();
  String v = stageVelText.getText();
  if (isInt(s) && isInt(v)) {
    int alt = int(s);
    int vel = int(v);
    displayText.scrollText("Sending Min Stage Altitude = " + str(alt));
    displayText.scrollText("Sending Min Stage Velocity = " + str(vel));
    theRocket.setStageAlt(alt, vel);
    stageAltUpdate = true;
    stageVelUpdate = true;
  } else {
    displayText.scrollText("Error: '" + s + "' or '" + v + "' may not be numbers");
  }
} //_CODE_:setStageAltButton:759707:

public void refreshButton_Click(GButton source, GEvent event) { //_CODE_:refreshButton:347793:
  theRocket.refreshSettings();
  siteAltUpdate = true;
  mainAltUpdate = true;
  goAltUpdate = true;
  stageAltUpdate = true;
  stageVelUpdate = true;
  displaySetting = true;
} //_CODE_:refreshButton:347793:

public void main_Clicked1(GCheckbox source, GEvent event) { //_CODE_:mainCheck:488158:
  theRocket.sendMain();
} //_CODE_:mainCheck:488158:

public void deploy_Clicked1(GCheckbox source, GEvent event) { //_CODE_:deployCheck:335480:
  theRocket.sendDeploy();
} //_CODE_:deployCheck:335480:

public void stage_Clicked1(GCheckbox source, GEvent event) { //_CODE_:stageCheck:583247:
  theRocket.sendStage();
} //_CODE_:stageCheck:583247:

public void chutePinCheckbox_Clicked1(GCheckbox source, GEvent event) { //_CODE_:chutePinCheck:786818:
  theRocket.toggleChuteLatch();
} //_CODE_:chutePinCheck:786818:

public void launchButton_Click1(GButton source, GEvent event) { //_CODE_:launchButton:787115:
  theRocket.setPreLaunch();
} //_CODE_:launchButton:787115:

public void holdButton_Click1(GButton source, GEvent event) { //_CODE_:holdButton:541915:
  theRocket.sendHold();
} //_CODE_:holdButton:541915:

public void annotateButton_Click1(GButton source, GEvent event) { //_CODE_:annotateButton:747646:
  theRocket.annotateFile(annotateText.getText());
} //_CODE_:annotateButton:747646:

public void annotateText_Enter1(GTextField source, GEvent event) { //_CODE_:annotateText:263647:
  //println("annotateText - GTextField event occured " + System.currentTimeMillis()%10000000 );
} //_CODE_:annotateText:263647:

public void sensorButton_Click1(GButton source, GEvent event) { //_CODE_:sensorButton:358453:
  theRocket.getSensorData();
} //_CODE_:sensorButton:358453:

public void accelButton_Click1(GButton source, GEvent event) { //_CODE_:accelButton:825505:
  //theRocket.getAccelData();
} //_CODE_:accelButton:825505:

public void flightButton_Click1(GButton source, GEvent event) { //_CODE_:flightButton:935290:
  theRocket.getFlightData();
} //_CODE_:flightButton:935290:

public void testButton_Click1(GButton source, GEvent event) { //_CODE_:testButton:808520:
  theRocket.sendTest();
} //_CODE_:testButton:808520:

public void armButton_Click1(GButton source, GEvent event) { //_CODE_:armButton:447426:
  theRocket.toggleArm();
} //_CODE_:armButton:447426:

public void fet1Button_Click1(GButton source, GEvent event) { //_CODE_:fet1Button:321977:
  theRocket.setFET(1);
} //_CODE_:fet1Button:321977:

public void fet2Button_Click1(GButton source, GEvent event) { //_CODE_:fet2Button:630600:
  theRocket.setFET(2);
} //_CODE_:fet2Button:630600:

public void recButton_Click1(GButton source, GEvent event) { //_CODE_:recButton:783492:
  theRocket.sendRecord();
} //_CODE_:recButton:783492:

public void connectButton_Click1(GButton source, GEvent event) { //_CODE_:connectButton:630754:
  theRocket.connect(serialPortMenu, connectButton, connectStatus, baud_rate, term);
  save_prefs();
  theRocket.refreshSettings();
} //_CODE_:connectButton:630754:

public void portMenu_Click1(GDropList source, GEvent event) { //_CODE_:serialPortMenu:611215:
  //println("serialPortMenu - GDropList event occured " + System.currentTimeMillis()%10000000 );
} //_CODE_:serialPortMenu:611215:

public void zeroAGL_click1(GButton source, GEvent event) { //_CODE_:zeroAGLbutton:302841:
  theRocket.alt_0 += theRocket.site_alt - theRocket.p_alt;
} //_CODE_:zeroAGLbutton:302841:



// Create all the GUI controls. 
// autogenerated do not edit
public void createGUI(){
  G4P.messagesEnabled(false);
  G4P.setGlobalColorScheme(GCScheme.CYAN_SCHEME);
  G4P.setCursor(ARROW);
  if(frame != null)
    frame.setTitle("Sketch Window");
  timeLabel = new GLabel(this, 25, 5, 80, 15);
  timeLabel.setText("Time");
  timeLabel.setTextBold();
  timeLabel.setLocalColorScheme(GCScheme.BLUE_SCHEME);
  timeLabel.setOpaque(false);
  FCtimeLabel = new GLabel(this, 25, 45, 80, 15);
  FCtimeLabel.setText("FC Time");
  FCtimeLabel.setTextBold();
  FCtimeLabel.setLocalColorScheme(GCScheme.BLUE_SCHEME);
  FCtimeLabel.setOpaque(false);
  altLabel = new GLabel(this, 410, 5, 80, 15);
  altLabel.setText("Altitude");
  altLabel.setTextBold();
  altLabel.setLocalColorScheme(GCScheme.BLUE_SCHEME);
  altLabel.setOpaque(false);
  gAltLabel = new GLabel(this, 405, 45, 90, 15);
  gAltLabel.setText("GPS Altitude");
  gAltLabel.setTextBold();
  gAltLabel.setLocalColorScheme(GCScheme.BLUE_SCHEME);
  gAltLabel.setOpaque(false);
  latLabel = new GLabel(this, 595, 5, 80, 15);
  latLabel.setText("Latitude");
  latLabel.setTextBold();
  latLabel.setLocalColorScheme(GCScheme.BLUE_SCHEME);
  latLabel.setOpaque(false);
  lonLabel = new GLabel(this, 595, 45, 80, 15);
  lonLabel.setText("Longitude");
  lonLabel.setTextBold();
  lonLabel.setLocalColorScheme(GCScheme.BLUE_SCHEME);
  lonLabel.setOpaque(false);
  siteLabel = new GLabel(this, 20, 160, 100, 20);
  siteLabel.setText("Site Altitude, ft");
  siteLabel.setLocalColorScheme(GCScheme.BLUE_SCHEME);
  siteLabel.setOpaque(false);
  mainAltLabel = new GLabel(this, 130, 160, 135, 20);
  mainAltLabel.setText("Main Chute Deploy, ft");
  mainAltLabel.setLocalColorScheme(GCScheme.BLUE_SCHEME);
  mainAltLabel.setOpaque(false);
  minGoLabel = new GLabel(this, 270, 160, 125, 20);
  minGoLabel.setText("Min GO Alt, ft");
  minGoLabel.setLocalColorScheme(GCScheme.BLUE_SCHEME);
  minGoLabel.setOpaque(false);
  stageAltLabel = new GLabel(this, 410, 160, 120, 20);
  stageAltLabel.setText("Min Stage Alt, ft");
  stageAltLabel.setLocalColorScheme(GCScheme.BLUE_SCHEME);
  stageAltLabel.setOpaque(false);
  minStageVLabel = new GLabel(this, 535, 160, 150, 20);
  minStageVLabel.setText("Min Stage Velocity, ft/s");
  minStageVLabel.setLocalColorScheme(GCScheme.BLUE_SCHEME);
  minStageVLabel.setOpaque(false);
  siteAltitudeText = new GTextField(this, 20, 181, 100, 20, G4P.SCROLLBARS_NONE);
  siteAltitudeText.setDefaultText("0");
  siteAltitudeText.setLocalColorScheme(GCScheme.BLUE_SCHEME);
  siteAltitudeText.setOpaque(true);
  siteAltitudeText.addEventHandler(this, "siteAlt_Enter");
  goAltitudeText = new GTextField(this, 280, 180, 100, 20, G4P.SCROLLBARS_NONE);
  goAltitudeText.setDefaultText("0");
  goAltitudeText.setLocalColorScheme(GCScheme.BLUE_SCHEME);
  goAltitudeText.setOpaque(true);
  goAltitudeText.addEventHandler(this, "goAlt_Enter");
  mainAltText = new GTextField(this, 150, 180, 100, 20, G4P.SCROLLBARS_NONE);
  mainAltText.setDefaultText("0");
  mainAltText.setLocalColorScheme(GCScheme.BLUE_SCHEME);
  mainAltText.setOpaque(true);
  mainAltText.addEventHandler(this, "mainAlt_Enter");
  stageAltText = new GTextField(this, 420, 180, 100, 20, G4P.SCROLLBARS_NONE);
  stageAltText.setLocalColorScheme(GCScheme.BLUE_SCHEME);
  stageAltText.setOpaque(true);
  stageAltText.addEventHandler(this, "stageAlt_Enter");
  stageVelText = new GTextField(this, 560, 180, 100, 20, G4P.SCROLLBARS_NONE);
  stageVelText.setDefaultText("0");
  stageVelText.setLocalColorScheme(GCScheme.BLUE_SCHEME);
  stageVelText.setOpaque(true);
  stageVelText.addEventHandler(this, "stageVtext_Enter1");
  setAltButton = new GButton(this, 20, 210, 100, 20);
  setAltButton.setText("Set Site Alt");
  setAltButton.setTextBold();
  setAltButton.addEventHandler(this, "setSiteAlt_Click1");
  setMainButton = new GButton(this, 150, 210, 100, 20);
  setMainButton.setText("Set Main Alt");
  setMainButton.setTextBold();
  setMainButton.addEventHandler(this, "mainAltButton_Click1");
  setGoAltButton = new GButton(this, 280, 210, 100, 20);
  setGoAltButton.setText("Set GO Alt");
  setGoAltButton.setTextBold();
  setGoAltButton.addEventHandler(this, "setGoAlt_Click1");
  setStageAltButton = new GButton(this, 490, 210, 110, 20);
  setStageAltButton.setText("Set Stage Min");
  setStageAltButton.setTextBold();
  setStageAltButton.addEventHandler(this, "setStageAlt_Click1");
  refreshButton = new GButton(this, 20, 270, 80, 20);
  refreshButton.setText("Refresh");
  refreshButton.setTextBold();
  refreshButton.addEventHandler(this, "refreshButton_Click");
  mainCheck = new GCheckbox(this, 155, 240, 122, 20);
  mainCheck.setText("Deploy Main");
  mainCheck.setTextAlign(GAlign.LEFT, GAlign.MIDDLE);
  mainCheck.setLocalColorScheme(GCScheme.BLUE_SCHEME);
  mainCheck.setOpaque(false);
  mainCheck.addEventHandler(this, "main_Clicked1");
  deployCheck = new GCheckbox(this, 285, 240, 130, 20);
  deployCheck.setText("Do Deployment");
  deployCheck.setTextAlign(GAlign.LEFT, GAlign.MIDDLE);
  deployCheck.setLocalColorScheme(GCScheme.BLUE_SCHEME);
  deployCheck.setOpaque(false);
  deployCheck.addEventHandler(this, "deploy_Clicked1");
  stageCheck = new GCheckbox(this, 500, 240, 90, 20);
  stageCheck.setText("Do Staging");
  stageCheck.setTextAlign(GAlign.LEFT, GAlign.MIDDLE);
  stageCheck.setLocalColorScheme(GCScheme.BLUE_SCHEME);
  stageCheck.setOpaque(false);
  stageCheck.addEventHandler(this, "stage_Clicked1");
  chutePinCheck = new GCheckbox(this, 155, 270, 156, 20);
  chutePinCheck.setText("Chute Latch Closed");
  chutePinCheck.setTextAlign(GAlign.LEFT, GAlign.MIDDLE);
  chutePinCheck.setLocalColorScheme(GCScheme.BLUE_SCHEME);
  chutePinCheck.setOpaque(false);
  chutePinCheck.addEventHandler(this, "chutePinCheckbox_Clicked1");
  launchButton = new GButton(this, 240, 85, 80, 15);
  launchButton.setText("Pre-Launch");
  launchButton.setTextBold();
  launchButton.addEventHandler(this, "launchButton_Click1");
  holdButton = new GButton(this, 145, 85, 80, 15);
  holdButton.setText("HOLD");
  holdButton.setTextBold();
  holdButton.addEventHandler(this, "holdButton_Click1");
  modeLabel = new GLabel(this, 25, 85, 80, 15);
  modeLabel.setText("Mode");
  modeLabel.setTextBold();
  modeLabel.setLocalColorScheme(GCScheme.BLUE_SCHEME);
  modeLabel.setOpaque(false);
  annotateButton = new GButton(this, 20, 310, 100, 20);
  annotateButton.setText("Annotate File");
  annotateButton.addEventHandler(this, "annotateButton_Click1");
  annotateText = new GTextField(this, 20, 340, 340, 20, G4P.SCROLLBARS_NONE);
  annotateText.setLocalColorScheme(GCScheme.BLUE_SCHEME);
  annotateText.setOpaque(true);
  annotateText.addEventHandler(this, "annotateText_Enter1");
  sensorButton = new GButton(this, 20, 580, 100, 20);
  sensorButton.setText("Sensor Data");
  sensorButton.setTextBold();
  sensorButton.addEventHandler(this, "sensorButton_Click1");
  accelButton = new GButton(this, 140, 580, 100, 20);
  accelButton.setText("Accel Data");
  accelButton.setTextBold();
  accelButton.addEventHandler(this, "accelButton_Click1");
  flightButton = new GButton(this, 260, 580, 100, 20);
  flightButton.setText("Flight Data");
  flightButton.setTextBold();
  flightButton.addEventHandler(this, "flightButton_Click1");
  testButton = new GButton(this, 480, 310, 80, 20);
  testButton.setText("Test");
  testButton.addEventHandler(this, "testButton_Click1");
  armButton = new GButton(this, 620, 310, 80, 20);
  armButton.setText("ARM");
  armButton.setTextBold();
  armButton.addEventHandler(this, "armButton_Click1");
  fet1Button = new GButton(this, 620, 340, 80, 20);
  fet1Button.setText("FET 1");
  fet1Button.setTextBold();
  fet1Button.addEventHandler(this, "fet1Button_Click1");
  fet2Button = new GButton(this, 620, 370, 80, 20);
  fet2Button.setText("FET 2");
  fet2Button.setTextBold();
  fet2Button.addEventHandler(this, "fet2Button_Click1");
  recButton = new GButton(this, 480, 370, 80, 20);
  recButton.setText("Record");
  recButton.setTextBold();
  recButton.addEventHandler(this, "recButton_Click1");
  portLabel = new GLabel(this, 480, 435, 80, 20);
  portLabel.setText("Serial Port");
  portLabel.setTextAlign(GAlign.LEFT, GAlign.MIDDLE);
  portLabel.setLocalColorScheme(GCScheme.BLUE_SCHEME);
  portLabel.setOpaque(false);
  connectStatus = new GLabel(this, 480, 485, 220, 60);
  connectStatus.setText("Disconnected");
  connectStatus.setTextAlign(GAlign.LEFT, GAlign.TOP);
  connectStatus.setLocalColorScheme(GCScheme.BLUE_SCHEME);
  connectStatus.setOpaque(false);
  connectButton = new GButton(this, 620, 435, 80, 20);
  connectButton.setText("Connect");
  connectButton.setTextBold();
  connectButton.addEventHandler(this, "connectButton_Click1");
  serialPortMenu = new GDropList(this, 480, 460, 220, 180, 10);
  serialPortMenu.setItems(loadStrings("list_611215"), 0);
  serialPortMenu.addEventHandler(this, "portMenu_Click1");
  aglLabel = new GLabel(this, 410, 85, 80, 15);
  aglLabel.setIcon("BLUE_SCHEME", 1, GAlign.RIGHT, GAlign.MIDDLE);
  aglLabel.setText("AGL");
  aglLabel.setTextBold();
  aglLabel.setOpaque(false);
  zeroAGLbutton = new GButton(this, 20, 240, 80, 20);
  zeroAGLbutton.setText("Zero AGL");
  zeroAGLbutton.setTextBold();
  zeroAGLbutton.addEventHandler(this, "zeroAGL_click1");
}

// Variable declarations 
// autogenerated do not edit
GLabel timeLabel; 
GLabel FCtimeLabel; 
GLabel altLabel; 
GLabel gAltLabel; 
GLabel latLabel; 
GLabel lonLabel; 
GLabel siteLabel; 
GLabel mainAltLabel; 
GLabel minGoLabel; 
GLabel stageAltLabel; 
GLabel minStageVLabel; 
GTextField siteAltitudeText; 
GTextField goAltitudeText; 
GTextField mainAltText; 
GTextField stageAltText; 
GTextField stageVelText; 
GButton setAltButton; 
GButton setMainButton; 
GButton setGoAltButton; 
GButton setStageAltButton; 
GButton refreshButton; 
GCheckbox mainCheck; 
GCheckbox deployCheck; 
GCheckbox stageCheck; 
GCheckbox chutePinCheck; 
GButton launchButton; 
GButton holdButton; 
GLabel modeLabel; 
GButton annotateButton; 
GTextField annotateText; 
GButton sensorButton; 
GButton accelButton; 
GButton flightButton; 
GButton testButton; 
GButton armButton; 
GButton fet1Button; 
GButton fet2Button; 
GButton recButton; 
GLabel portLabel; 
GLabel connectStatus; 
GButton connectButton; 
GDropList serialPortMenu; 
GLabel aglLabel; 
GButton zeroAGLbutton; 

